<template>
  <div class="layout-all">
    <control :config="config" />
    <div class="layout-header" style="float:left">
      <!-- <router-link to="/user_abt/user/form">
        <el-button
          type="primary"
          icon="el-icon-plus"
          style="margin-left:0px"
        >添加</el-button>
      </router-link> -->
    </div>
    <div class="layout-content">
      <el-table
        :data="tableData"
        stripe
        align="center"
        highlight-current-row
        style="width: 100%;margin-top:50px"
      >
        <el-table-column align="center" prop="id" label="编号" width="80" :fixed="isMobile()?'left':undefined"/>
        <el-table-column align="center" prop="account" label="账号" width="200" />
        <el-table-column align="center" prop="nickname" label="昵称" width="200" />
        <el-table-column align="center" prop="card_name" label="真实姓名" width="100" />
        <el-table-column align="center" prop="card_number" label="身份证号码" width="200" />
        <el-table-column align="center" prop="thumb" label="身份证正面">
          <template slot-scope="scope">
            <el-popover
            placement="right"
            trigger="hover">
            <img :src="scope.row.thumb" class="imgStyle" style="max-height: 450px;max-width: 450px"/>
            <img slot="reference" :src="scope.row.thumb" style="max-height: 50px;max-width: 150px">
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="thumb_back" label="身份证背面">
          <template slot-scope="scope">
            <el-popover
            placement="right"
            trigger="hover">
            <img :src="scope.row.thumb_back" class="imgStyle" style="max-height: 450px;max-width: 450px"/>
            <img slot="reference" :src="scope.row.thumb_back" style="max-height: 50px;max-width: 150px">
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="status" label="状态" width="100">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.status == 3 ?'success':scope.row.status == 2 ? 'primary' : 'warning'"
              size="small"
            >{{ scope.row.status == 3 ? "已通过" :scope.row.status == 2 ?"已拒绝": "申请中" }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="create_time" label="申请日期" width="180" />
        <el-table-column
          align="center"
          prop="telephone"
         :fixed="isMobile()?undefined:'right'"
          width="240"
          label="操作"
        >
          <template slot-scope="scope" >
            <el-button type="success" v-if="scope.row.status<2" size="small" @click="onStatus(scope.row.id,3)" >通过</el-button>
             <el-button type="danger" v-if="scope.row.status<2" size="small" @click="onStatus(scope.row.id,2)" >拒绝</el-button>
             <el-button type="primary" v-if="scope.row.status==3" size="small" @click="onStatus(scope.row.id,2)" >重置</el-button>

          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="current_page"
      :page-size="per_page"
      layout="total, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import control from '../../components/control/control'
export default {
  name:'user_card_index',
  components: { control },
  data() {
    return {
      config: [
        { type: 'text', placeholder: '请输入用户名或编号', field: 'title', val: '' }
      ],
      dateTime: '',
      value: '',
      searchWhere: {
        title: ''
      },
      tableData: [],
      total: 0,
      current_page: 1,
      per_page: 14,
    }
  },
  activated(){
    if(this.$getUpdate()){
      this.onSearch()
    }
  },
  created() {
    this.onSearch()
  },
  methods: {
    // 查询
    handleSizeChange(val) {
      this.onSearch()
    },
    handleCurrentChange(val) {
      this.current_page = val
      this.onSearch()
    },
    onSearch() {
      const form = {}
      form.page = this.current_page
      form.map = this.searchWhere
      this.get('/admin/UserCard/index', form, 'POST').then(e => {
        this.tableData = e.list.data
        this.per_page = e.list.per_page
        this.total = e.list.total
        this.current_page = e.list.current_page
      })
    },
    // 添加
    onAdd() {},
    // 编辑
    onEdit(id) {
      console.log(id)
    },
    // 删除
    onStatus(id,val) {
      const form={
        id:id,
        val:val,
        field:'status',
      }
      this.get('/admin/UserCard/update', form, 'POST').then(e => {
        this.tableData.forEach(function(item,i,a){
          if(item.id==id)a[i].status=val
        })
      })
    }
  }
}
</script>

<style>
.layout-all {
  margin-top: 20px;
  margin-left: 10px;
}
.layout-content {
  margin-top: 20px;
}
</style>>
